package com.open.capacity.prints.controller;

import com.open.capacity.commons.PageResult;
import com.open.capacity.commons.Result;
import com.open.capacity.prints.entity.BillGhsfpt;
import com.open.capacity.prints.service.BillGhsfptService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * 工行收费凭条
 *
 * @author
 * @email
 * @date 2021-04-07 09:40:45
 */
@RestController
@RequestMapping("ghsfpts")
@Api(tags = "工行收费凭条")
public class BillGhsfptController {

    @Autowired
    private BillGhsfptService billGhsfptService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('bill_ghsfpt:billghsfpt:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = billGhsfptService.pageAll(params);
        return pageResult;
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findByFkrFullname")
    @PreAuthorize("hasAnyAuthority('bill_ghsfpt:billghsfpt:list')")
    public Result findByFkrFullname(String fkrFullname) {
        return Result.succeed(billGhsfptService.findByFkrFullname(fkrFullname));
    }

    /**
     * 查询单条记录
     */
    @RequestMapping("/findById")
    @PreAuthorize("hasAnyAuthority('bill_ghsfpt:billghsfpt:list')")
    public Result findById(String id) {
        return Result.succeed(billGhsfptService.findById(id));
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('bill_ghsfpt:billghsfpt:save')")
    public Result save(@RequestBody @Valid BillGhsfpt billGhsfpt, String keyValue) {
        if (StringUtils.isEmpty(keyValue)) {
            keyValue = billGhsfptService.save(billGhsfpt);
        } else {
            billGhsfpt.setId(keyValue);
            keyValue = billGhsfptService.update(billGhsfpt);
        }
        return Result.succeed(keyValue,"保存成功");
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('bill_ghsfpt:billghsfpt:delete')")
    public Result delete(@PathVariable String id) {
        billGhsfptService.delete(id);
        return Result.succeed("删除成功");
    }

}
